00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef DEGLOBALTYPES_HPP
00029 #define DEGLOBALTYPES_HPP
00030
00031 #define _DEQUOTE(x) #x
00032 #define DESTRINGIZE_VALUE(x) _DEQUOTE(x)
00033
00034 #include "deOS.hpp"
00035 #include <cstring>
00036 #include <cstdlib>
00037
00038
00039 #define DE_DOUBLE_PRECISION (1)
00040
00041
00042
00043
00044
00045
00046
00047 typedef char deBoolean;
00048 typedef float deFloat;
00049 #ifdef DE_DOUBLE_PRECISION
00050 typedef double deDouble;
00051 #define COS cos
00052 #define SIN sin
00053 #define TAN tan
00054 #define ACOS acos
00055 #define ASIN asin
00056 #define ATAN atan
00057 #else
00058 typedef float deDouble;
00059 #define COS cosf
00060 #define SIN sinf
00061 #define TAN tanf
00062 #define ACOS acosf
00063 #define ASIN asinf
00064 #define ATAN atanf
00065 #endif
00066 typedef unsigned long deARGB;
00067 typedef unsigned short deWorldID;
00068 typedef unsigned long deObjectID;
00069
00070
00071
00072 typedef unsigned long DWORD;
00073 typedef int BOOL;
00074 typedef unsigned char BYTE;
00075 typedef unsigned short WORD;
00076 typedef float FLOAT;
00077 typedef FLOAT* PFLOAT;
00078 typedef BOOL* LPBOOL;
00079 typedef BYTE* LPBYTE;
00080 typedef int* LPINT;
00081 typedef WORD* LPWORD;
00082 typedef long* LPLONG;
00083 typedef DWORD* LPDWORD;
00084 typedef void* LPVOID;
00085 typedef const void* LPCVOID;
00086 typedef int INT;
00087 typedef unsigned int UINT;
00088 typedef unsigned int* PUINT;
00089
00090 typedef unsigned char byte;
00091
00092 typedef byte BYTE;
00093 typedef unsigned short WORD;
00094 typedef unsigned int UINT;
00095 typedef int INT;
00096 typedef long LONG;
00097 typedef unsigned long DWORD;
00098
00099 typedef void * HANDLE;
00100
00101
00102 typedef signed char s8;
00103 typedef signed short s16;
00104 typedef signed long s32;
00105
00106 typedef unsigned char u8;
00107 typedef unsigned short u16;
00108 typedef unsigned long u32;
00109
00110
00111 #ifdef DE3D_HANDLES_ARE_VOID
00112 typedef void * HWND;
00113 typedef void * HINSTANCE;
00114 typedef void * HMONITOR;
00115 #else
00116 typedef struct HWND__* HWND;
00117 typedef struct HINSTANCE__* HINSTANCE;
00118 typedef struct HMONITOR__* HMONITOR;
00119 #endif
00120 typedef HINSTANCE HMODULE;
00121
00122 #if defined(DE3D_INT64_IS_LONG_LONG)
00123 typedef signed long long s64;
00124 typedef unsigned long long u64;
00125 #elif defined(DE3D_INT64_IS_MS_INT64)
00126 typedef signed __int64 s64;
00127 typedef unsigned __int64 u64;
00128 #endif
00129
00130
00131
00132
00133
00134
00135
00136 const deBoolean DE_TRUE = 1;
00137 const deBoolean DE_FALSE = 0;
00138 #define deTRUE (DE_TRUE)
00139 #define deFALSE (DE_FALSE)
00140
00141 #define ARGB(a,r,g,b) \
00142 ((DWORD)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
00143 #define GrabARGB(argb,a,r,g,b)\
00144 {a=((argb>>24)&0xff); r=((argb>>16)&0xff); g=((argb>>8)&0xff); b=((argb)&0xff); }
00145
00146 #define deXOR(x,y) ( (!(x)&&(y)) || ((x)&&!(y)) )
00147
00148 #ifndef max
00149 #define max(a,b) (((a) > (b)) ? (a) : (b))
00150 #endif
00151
00152 #ifndef min
00153 #define min(a,b) (((a) < (b)) ? (a) : (b))
00154 #endif
00155
00156 #define LEAK_HUNTING // comment out to disable leak-hunts
00157 #ifndef __GNUC__
00158 #ifdef LEAK_HUNTING
00159 #ifdef _DEBUG
00160
00161 #define _CRTDBG_MAP_ALLOC
00162 #include <crtdbg.h>
00163 #undef malloc
00164 #define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
00165 #define malloc(s) _malloc_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
00166 #define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
00167 #define free(p) _free_dbg(p, _NORMAL_BLOCK)
00168 #endif // _DEBUG
00169 #endif
00170 #endif
00171
00172 #if defined(_MSC_VER) && 0
00173
00174 #define for if(0){}else for
00175 #endif
00176
00177
00178 #undef FAR
00179 #define FAR
00180
00181 #define DETAILED_DEBUG_REPORT (1)
00182 #define NOTIFY_BAD_RETURNS (1)
00183
00184 #if defined(DETAILED_DEBUG_REPORT) && DETAILED_DEBUG_REPORT && defined(_DEBUG) && !defined(__GNUC__)
00185 #if defined(NOTIFY_BAD_RETURNS) && NOTIFY_BAD_RETURNS
00186 #define _DEBUG_RETURN_LEVEL _CRT_ASSERT
00187 #else // NOTIFY_BAD_RETURNS
00188 #define _DEBUG_RETURN_LEVEL _CRT_WARN
00189 #endif // NOTIFY_BAD_RETURNS
00190 #include <crtdbg.h>
00191
00192 static inline void BREAK_EXECUTION() {_asm{int 3}}
00193 #define DEBUGMSG0(msg) if (1 == _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, "%s\n", msg)) BREAK_EXECUTION()
00194 #define DEBUGMSG1(fmt,arg1) if (1 == _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, fmt"\n", arg1)) BREAK_EXECUTION()
00195 #define DEBUGMSG2(fmt,arg1,arg2) if (1 == _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, fmt"\n", arg1, arg2)) BREAK_EXECUTION()
00196 #define DEBUGMSG3(fmt,arg1,arg2,arg3) if (1 == _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, fmt"\n", arg1, arg2, arg3)) BREAK_EXECUTION()
00197 #define DEBUGMSG4(fmt,arg1,arg2,arg3,arg4) if (1 == _CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, fmt"\n", arg1, arg2, arg3, arg4)) BREAK_EXECUTION()
00198 #define DEBUGRETURN(retval,message) if (1 == _CrtDbgReport(_DEBUG_RETURN_LEVEL, __FILE__, __LINE__, NULL, "WARNING\n%s\nRETURNING %s\n", message, #retval))\
00199 {BREAK_EXECUTION();return retval;} else return retval
00200 #define DEBUGRETURNNOVAL(message) if (1 == _CrtDbgReport(_DEBUG_RETURN_LEVEL, __FILE__, __LINE__, NULL, "WARNING\n%s\nRETURNING void\n", message))\
00201 {BREAK_EXECUTION();return;} else return
00202 #define DEBUG_EXP_RETURN(exp,retval) if (exp) {} else if (1 == _CrtDbgReport(_DEBUG_RETURN_LEVEL, __FILE__, __LINE__, NULL, "%s\nRETURNING %s\n", #exp, #retval))\
00203 {BREAK_EXECUTION();return retval;} else return retval
00204 #define DEBUG_EXP_RETURNMSG(exp,retval,msg) if (exp) {} else if (1 == _CrtDbgReport(_DEBUG_RETURN_LEVEL, __FILE__, __LINE__, NULL, "%s\nMESSAGE:\n%s\nRETURNING %s\n", #exp, msg, #retval))\
00205 {BREAK_EXECUTION();return retval;} else return retval
00206 #define DE_ASSERT(exp) if (exp) {} else if (1 != _CrtDbgReport(_DEBUG_RETURN_LEVEL, __FILE__, __LINE__, NULL, "%s", #exp)) {} else BREAK_EXECUTION()
00207 #define DEBUG_ONLY(exp) exp
00208 #else // DETAILED_DEBUG_REPORT
00209 static inline void BREAK_EXECUTION() {}
00210 #define DEBUGMSG0(msg)
00211 #define DEBUGMSG1(fmt,arg1)
00212 #define DEBUGMSG2(fmt,arg1,arg2)
00213 #define DEBUGMSG3(fmt,arg1,arg2,arg3)
00214 #define DEBUGMSG4(fmt,arg1,arg2,arg3,arg4)
00215 #define DEBUGRETURN(retval,message) return retval
00216 #define DEBUGRETURNNOVAL(message) return
00217 #define DEBUG_EXP_RETURN(exp,retval)
00218 #define DEBUG_EXP_RETURNMSG(exp,retval,msg)
00219 #define DE_ASSERT(exp)
00220 #define DEBUG_ONLY(exp)
00221 #endif // DETAILED_DEBUG_REPORT
00222
00223
00224
00225
00226
00227 enum deResult
00228 {
00229 deFAILED = 0,
00230 deSUCCEEDED,
00231 deCRITICALERROR,
00232 _deResult_Force32bit = 0x7fffffff
00233 };
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 DE3D_INTERFACE_(IdeRefCountBase)
00244 {
00245 protected:
00246 virtual ~IdeRefCountBase() {}
00247 public:
00248
00249
00250 virtual s32 Claim() = 0;
00251
00252
00253 virtual s32 Release() = 0;
00254 };
00255 struct deIDPair
00256 {
00257 deWorldID wid;
00258 deObjectID oid;
00259 };
00260 struct deVec3d
00261 {
00262 union { deDouble x; deDouble X; };
00263 union { deDouble y; deDouble Y; };
00264 union { deDouble z; deDouble Z; };
00265
00266
00267 };
00268 struct deVec3f
00269 {
00270 union { deFloat x; deFloat X; };
00271 union { deFloat y; deFloat Y; };
00272 union { deFloat z; deFloat Z; };
00273
00274
00275
00276 };
00277 typedef deVec3f deVertex;
00278 struct deColor
00279 {
00280 deFloat r,g,b,a;
00281
00282
00283 };
00284 struct deRect
00285 {
00286 long Left;
00287 long Top;
00288 long Right;
00289 long Bottom;
00290
00291
00292
00293 };
00294 struct deFloatRect
00295 {
00296 deFloat Top;
00297 deFloat Left;
00298 deFloat Bottom;
00299 deFloat Right;
00300
00301
00302
00303 };
00304 struct dePlane
00305 {
00306 deVec3d Norm;
00307 deDouble Dist;
00308
00309
00310
00311 };
00312 struct deBoundSphere
00313 {
00314 deVec3d Center;
00315 deDouble Radius;
00316
00317
00318
00319 };
00320 struct deAABB
00321 {
00322 deVec3d Min;
00323 deVec3d Max;
00324
00325
00326
00327 };
00328 struct deOBB
00329 {
00330 deVec3d Corner;
00331 deVec3d Offset[3];
00332 };
00333 struct deTexCoord1
00334 {
00335 deFloat u;
00336
00337
00338 };
00339 struct deTexCoord2
00340 {
00341 deFloat u;
00342 deFloat v;
00343
00344
00345
00346
00347
00348 };
00349 struct deTexCoord3
00350 {
00351 deFloat u;
00352 deFloat v;
00353 deFloat w;
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 };
00364 struct deTexCoord4
00365 {
00366 deFloat u;
00367 deFloat v;
00368 deFloat w;
00369 deFloat t;
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 };
00380
00381
00382
00383
00384
00385
00386
00387 typedef deTexCoord2 deTexCoord;
00388 struct deLVert
00389 {
00390 deVec3d Pos;
00391 deVec3d Norm;
00392 deColor Color;
00393 deTexCoord UV;
00394 };
00395
00396
00397 class deRefCountBase : virtual public IdeRefCountBase
00398 {
00399 private:
00400 s32 m_NumClaims;
00401 protected:
00402 deRefCountBase() : m_NumClaims(1) {}
00403 virtual ~deRefCountBase() {}
00404 public:
00405 s32 Claim()
00406 { ++m_NumClaims;
00407 return m_NumClaims;
00408 }
00409 s32 Release()
00410 { --m_NumClaims;
00411 if (m_NumClaims == 0)
00412 { delete this;
00413 return 0;
00414 }
00415 return m_NumClaims;
00416 }
00417 };
00418
00419
00420
00421
00422
00423 const deDouble DE_PI = (deDouble)3.14159265358979323846;
00424 const deDouble DE_ONEOVERPI = (deDouble)0.318309886183790671;
00425 const deVec3d deZeroVec = {0,0,0};
00426 const deVec3d deOneVec = {1,1,1};
00427 const deVec3d deVecX = {1,0,0};
00428 const deVec3d deVecY = {0,1,0};
00429 const deVec3d deVecZ = {0,0,1};
00430 const deTexCoord deZeroTex = {0,0};
00431
00432
00433
00434
00435 #pragma warning (disable : 4244)
00436 static inline deColor deMake_Color(deARGB in) { deColor ret = {((in>>16)&0xFF)/255.0f, ((in>>8)&0xFF)/255.0f, (in&0XFF)/255.0f, ((in>>24)&0xFF)/255.0f}; return ret;}
00437 static inline deARGB deMake_Color(deColor &in) { deARGB ret = ((deARGB(in.a*255))<<24) | ((deARGB(in.r*255))<<16) | ((deARGB(in.g*255))<<8) | ((deARGB(in.b*255))); return ret; }
00438 static inline deVec3d deMake_Vec3d(deDouble x, deDouble y, deDouble z) {deVec3d ret = {x,y,z}; return ret;}
00439 static inline deVec3d deMake_Vec3d(const deVertex & vec) {deVec3d ret = {vec.x,vec.y,vec.z}; return ret;}
00440 static inline deVertex deMake_Vertex(deFloat x, deFloat y, deFloat z) {deVertex ret = {x,y,z}; return ret;}
00441 static inline deVertex deMake_Vertex(const deVec3d & vec) {deVertex ret = {(deFloat)vec.x,(deFloat)vec.y,(deFloat)vec.z}; return ret;}
00442 static inline deTexCoord deMake_TexCoord(deFloat u_, deFloat v_) { deTexCoord ret = {u_, v_}; return ret; }
00443 static inline void deMake_TexCoord(deTexCoord1& target, const deTexCoord2& tex2) { target.u = tex2.u; }
00444 static inline void deMake_TexCoord(deTexCoord1& target, const deTexCoord3& tex3) { target.u = tex3.u; }
00445 static inline void deMake_TexCoord(deTexCoord1& target, const deTexCoord4& tex4) { target.u = tex4.u; }
00446 static inline void deMake_TexCoord(deTexCoord2& target, const deTexCoord1& tex1) { target.u = tex1.u; target.v = 0; }
00447 static inline void deMake_TexCoord(deTexCoord2& target, const deTexCoord3& tex3) { target.u = tex3.u; target.v = tex3.v; }
00448 static inline void deMake_TexCoord(deTexCoord2& target, const deTexCoord4& tex4) { target.u = tex4.u; target.v = tex4.v; }
00449 static inline void deMake_TexCoord(deTexCoord3& target, const deTexCoord1& tex1) { target.u = tex1.u; target.v = 0; target.w = 0; }
00450 static inline void deMake_TexCoord(deTexCoord3& target, const deTexCoord2& tex2) { target.u = tex2.u; target.v = tex2.v; target.w = 0; }
00451 static inline void deMake_TexCoord(deTexCoord3& target, const deTexCoord4& tex4) { target.u = tex4.u; target.v = tex4.v; target.w = tex4.w; }
00452 static inline void deMake_TexCoord(deTexCoord4& target, const deTexCoord1& tex1) { target.u = tex1.u; target.v = 0; target.w = 0; target.t = 0; }
00453 static inline void deMake_TexCoord(deTexCoord4& target, const deTexCoord2& tex2) { target.u = tex2.u; target.v = tex2.v; target.w = 0; target.t = 0; }
00454 static inline void deMake_TexCoord(deTexCoord4& target, const deTexCoord3& tex3) { target.u = tex3.u; target.v = tex3.v; target.w = tex3.w; target.t = 0; }
00455 #pragma warning (default : 4244)
00456
00457
00458
00459
00460 #define DEG2RAD(d) ((d)*(DE_PI/180.0))
00461 #define RAD2DEG(r) ((r)*(180*DE_ONEOVERPI))
00462
00463 #define DE3D_SAFE_DELETE(p) if(!p) {} else delete (p); (p)=NULL
00464 #define DE3D_SAFE_DELETE_ARRAY(p) if(!p) {} else delete[] (p); (p)=NULL
00465 #define DE3D_SAFE_RELEASE(p) if(!p) {} else (p)->Release(); (p)=NULL
00466
00467
00468 #define _TODO
00469 #define _PRINT_NOTES
00470 #ifdef _TODO
00471 #define __DE_FILE__LINE__ __FILE__ "(" DESTRINGIZE_VALUE(__LINE__) "): "
00472
00473 #define TODO(x) message(__DE_FILE__LINE__"\n"\
00474 "+--------------------------------\n"\
00475 "| TODO : " #x "\n"\
00476 "+--------------------------------\n")
00477 #define FIXME(x) message(__DE_FILE__LINE__"\n"\
00478 "+--------------------------------\n"\
00479 "| FIXME: " #x "\n"\
00480 "+--------------------------------\n")
00481
00482 #ifdef _PRINT_NOTES
00483 #define note(x) message(__DE_FILE__LINE__ "NOTE: " #x "\n")
00484 #else
00485 #define note(x) _BLANK_PRAGMA
00486 #endif
00487 #define todo(x) message(__DE_FILE__LINE__ "TODO: " #x "\n")
00488 #define fixme(x) message(__DE_FILE__LINE__ "FIXME: " #x "\n")
00489 #else
00490 #define _BLANK_PRAGMA
00491 #define TODO(x) _BLANK_PRAGMA
00492 #define FIXME(x) _BLANK_PRAGMA
00493 #define note(x) _BLANK_PRAGMA
00494 #define todo(x) _BLANK_PRAGMA
00495 #define fixme(x) _BLANK_PRAGMA
00496 #endif
00497
00498
00499 #endif //End DEGLOBALTYPES_HPP
00500